<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="inPut" />
		        <input type="button" value="阶乘" onclick="result()" />
		        <span id="result">  </span>
		        <script type="text/javascript">
		            function result() {
		                var num = parseInt(document.getElementById('inPut').value);
		                var result = document.getElementById('result');
		                var anser = 1;
		                if (!num&&num!=0) {
		                    result.innerHTML = '请输入一个数字';
		                    return;
		                }
		                if (num < 0) {
		                    result.innerHTML = '负数没有阶乘';
		                } else if (num == 0) {
		                    result.innerHTML = '=1';
		                } else {
		                    for (let i = 1; i <= num; i++) {
		                        anser *= i;
		                        
		                    }
		                    result.innerHTML = '='+anser;
		                }
		                
		            }
		        </script>
	</body>
</html>
